home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 441 / dlibs12 / open.c < prev    next >
C/C++ Source or Header  |  1990-11-23  |  781b  |  40 lines

  1. #include <osbind.h>
  2. #include <stdio.h>
  3. #include <fcntl.h>
  4. #include <errno.h>
  5.  
  6. int open(filename, iomode, pmode)
  7.     register char *filename;
  8.     register int iomode, pmode;
  9.     {
  10.     register int rv;
  11.  
  12.     if(access(filename, 0x00))        /* file exists */
  13.         {
  14.         if((iomode & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
  15.             return(errno = EEXIST);
  16.         if(iomode & O_TRUNC)
  17.             rv = creat(filename, 0x00);
  18.         else
  19.             rv = Fopen(filename, (0x03 & iomode));
  20.         }
  21.     else                    /* file doesn't exist */
  22.         {
  23.         if(iomode & O_CREAT)
  24.             rv = creat(filename, pmode);
  25.         else
  26.             rv = EFILNF;
  27.         }
  28.     if((rv >= 0) && (iomode & O_APPEND))
  29.         lseek(rv, 0L, SEEK_END);
  30.     if(rv < (-3))
  31.         errno = rv;
  32.     return(rv);
  33.     }
  34.  
  35. int close(handle)
  36.     int handle;
  37.     {
  38.     return(errno = ((int) Fclose(handle)));
  39.     }
  40.